const net = require('net')
const {rl} = require('./utils')


function bar(){
  return new Promise((resolve, reject)=>{
    rl.question('Enter: ', data=>resolve(data))
  })
}

const client = net.createConnection({
  port: 8000
}, async ()=>{
  console.log('connect to server!')

  let data = await bar()

  client.write(data)
  
})


client.on('data', (data)=>{
  console.log(data.toString())
  client.end()
})


client.on('end', ()=>{
  console.log('disconnect from server!')
})


